package com.think.teaching.mapper;

import com.think.teaching.model.Course;
import com.think.teaching.model.ExamPaper;

import java.util.Map;

import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * <p>
 * 试卷 Mapper 接口
 * </p>
 *
 * @author think
 * @since 2020-08-12
 */
public interface 	ExamPaperMapper extends BaseMapper<ExamPaper> {

	@Select("<script>" +
			"SELECT e.*,course.course_name FROM exam_paper e LEFT JOIN course ON course.id=e.course_id  WHERE e.delflag=0 " 
			+
			"<if test='type gt 0'>AND e.type=#{type}</if>"
			+
			"<if test='state gt 0'> AND e.state =#{state}</if>"
			+
			"<if test='type gt 0'> AND e.type = #{type}</if>"
			+
			"<if test='course gt 0'> AND e.course_id = #{course}</if>"
			+
			"<if test='tag gt 0'> AND e.id IN(SELECT paper_tag.paper_id FROM paper_tag WHERE tag=#{tag})</if>"
			+
			"</script>"
	)
	IPage<Map<String, Object>> selectPaperWithFilter(IPage<Map<String, Object>> page,
													 @Param("type") Integer type,
													 @Param("tag") Integer tag,
													 @Param("state") Integer state,
													 @Param("course") Integer course);
}
